from typing import List

from afast_core.core_tools.snow_flake_helper import Snow
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.services.service_businesses import \
    Businesses



class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    ids: List[int]
    appid: str
    dc_number: str


class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class InfirmaryBusinessesDoctorUserSchedulingBatchDelController(IController):

    def business_login(self):
        pass

        # 先删除缓存再清理数据库？
        # 注意需要同时的删除缓存记录信息，看看这个目前是否必须

        # 设置 key避免多次的重复设置
        sync_redis_client = self.request.app.sync_redis
        # 先根据IDS获取到对于的字段所属的日期和医生信息等
        idsinfo = Businesses.get_businesses_doctor_user_scheduling_batch_info_byids(
            appid=self.schema_param.appid,
            dc_number=self.schema_param.dc_number,
            ids=self.schema_param.ids
        )
        for item in idsinfo:
            # 删除缓存的key
            stock_ismsl_s_make_key = f"ismsl_s_make:{item.get('appid')}：{item.get('si_number')}:{item.get('dc_number')}:{str(item.get('scheduling_dnotime'))}:{str(item.get('scheduling_dnotime'))} {item.get('scheduling_tiemampmstr')}:00"
            sync_redis_client.delete(stock_ismsl_s_make_key)

        # 再删除实体数据
        result = Businesses.del_businesses_doctor_user_scheduling_batch_info_byid(
            appid=self.schema_param.appid,
            dc_number=self.schema_param.dc_number,
            ids=self.schema_param.ids)

        if result:
            self.response_msg = '删除成功'
        else:
            self.response_ok = False
            self.response_msg = '删除失败'
            return None
